import request from '@/util/request'
import qs from 'qs'
import md5 from 'js-md5'

// 账号密码登录
export function passwordLogin(username, password) {
  const data = {
    username,
    password: md5(password)
  }
  return request({
    url: '/login/user/password.json',
    method: 'post',
    data: qs.stringify(data),
    headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function sendMobile(headers, mobile) {
  return request({
    url: `/code/person/login/${mobile}.json`,
    method: 'get',
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function sendEmail(headers, email) {
  return request({
    url: `/code/company/login/${email}.json`,
    method: 'get',
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

// 账号验证码登录
export function codeLogin(username, code, uuid) {
  const data = {
    username,
    code
  }
  return request({
    url: '/login/user/code.json',
    method: 'post',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
      uuid
    },
    baseURL: process.env.VUE_APP_AJS_USER
  })
}
